package io.dshubs.archives.controller;


import io.dshubs.archives.entity.ArchiveDestroy;
import io.dshubs.archives.entity.ArchiveFileResource;
import io.dshubs.archives.entity.ArchiveSpecialFeature;
import io.dshubs.archives.service.ArchiveFileResourceService;
import io.dshubs.commons.log.annotation.LogOperation;
import io.dshubs.commons.security.user.SecurityUser;
import io.dshubs.commons.tools.page.PageData;
import io.dshubs.commons.tools.utils.Result;
import io.dshubs.commons.tools.validator.ValidatorUtils;
import io.dshubs.commons.tools.validator.group.AddGroup;
import io.dshubs.commons.tools.validator.group.DefaultGroup;
import io.dshubs.commons.tools.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 档案文件表  前端控制器
 * </p>
 *
 * @author mao
 * @since 2021-09-07
 */
@Api(tags = "档案文件表")
@RestController
@RequestMapping("/FileResource")
public class ArchiveFileResourceController {

    @Autowired
    private ArchiveFileResourceService archiveFileResourceService;

    @GetMapping("page")
    @ApiOperation("档案文件:page")
    public Result<PageData<ArchiveFileResource>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        return new Result<PageData<ArchiveFileResource>>().ok(archiveFileResourceService.page(params));
    }


    @GetMapping("{id}")
    @ApiOperation("详情")
    @LogOperation("档案文件查询:get")
    public Result<ArchiveFileResource> get(@PathVariable("id") Long id){
        return new Result<ArchiveFileResource>().ok(archiveFileResourceService.selectById(id));
    }

    @PostMapping
    @ApiOperation("保存")
    @LogOperation("档案文件新增:save")
    public Result save(@RequestBody ArchiveFileResource archiveFileResource){
        //效验数据
        ValidatorUtils.validateEntity(archiveFileResource, AddGroup.class, DefaultGroup.class);

        archiveFileResourceService.insert(archiveFileResource);
        return new Result();
    }

    @PutMapping
    @ApiOperation("修改")
    @LogOperation("档案文件修改:update")
    public Result update(@RequestBody ArchiveFileResource archiveFileResource){

        ValidatorUtils.validateEntity(archiveFileResource, UpdateGroup.class, DefaultGroup.class);

        archiveFileResourceService.updateById(archiveFileResource);

        return new Result();
    }
    @DeleteMapping
    @ApiOperation("删除")
    @LogOperation("档案文件删除:delete")
    public Result delete(@RequestBody @NotNull(message = "批量删除id不能为空") List<Long> ids){
        archiveFileResourceService.deleteBatchIds(ids);
        return new Result();
    }




}
